import useUserStore from '@/stores'
import axios, { type InternalAxiosRequestConfig } from 'axios'

axios.defaults.baseURL = 'http://119.29.41.94:8080/'

const request =()=>{
  axios.interceptors.request.use(
    (config: InternalAxiosRequestConfig) => {
      if (config.headers) {
        const store = useUserStore()
        config.headers.Authorization = `Bearer ${store.$state.token}`
      }
      return config
    },
    (error) => {
      return Promise.reject(error)
    }
  )
}

export default request
// const request = axios.create({
//   baseURL: import.meta.env.VITE_API_URL,
//   timeout: 10000
// })

// export default axios
// jike
// import HYRequest from './req'

// const hyRequest  = new HYRequest({

//   interceptors: {
//     requestSuccessFn: (config) => {
//       axios.interceptors.request.use(
//         (config: InternalAxiosRequestConfig) => {
//           if (config.headers) {
//             const store = useUserStore()
//             config.headers.Authorization = `Bearer ${store.$state.token}`
//           }
//           return config
//         },
//         (error) => {
//           return Promise.reject(error)
//         }
//       )
//     }
//   }
// })
